<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * This class is used to store and retrieve file cache
 *
 * @author Zelic
 */
class Lib_ZelCache {

    static $cachePath;

    static function init() {
        Lib_ZelCache::$cachePath = 'res/cache/';
    }

    static function exist($key) {
        if (file_exists(Lib_ZelCache::$cachePath . $key)) {
            return true;
        }
        return false;
    }

    static function put($key, $value) {
        $file = fopen(Lib_ZelCache::$cachePath . $key, 'w');
        fwrite($file, $value);
        fclose($file);
        return true;
    }

    static function get($key) {
        if (Lib_ZelCache::exist($key)) {
            $value = file_get_contents(Lib_ZelCache::$cachePath . $key);
            return $value;
        }
        return false;
    }
    
    static function flush(){
        $files = scandir(Lib_ZelCache::$cachePath);
        foreach ($files as $file){
            if ($file!='.'&&$file!='..'&&$file!='.svn'){
                unlink(Lib_ZelCache::$cachePath.$file);
            }
        }
    }

}

?>
